import { defineConfig } from 'vite';
import path from 'node:path';
import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
import px2viewport from 'postcss-px-to-viewport';
import autoprefixer from 'autoprefixer';
import checker from 'vite-plugin-checker';

// https://vite.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@': path.join(__dirname, './src'),
    },
  },
  css: {
    postcss: {
      plugins: [
        px2viewport({
          unitToConvert: 'px',
          viewportWidth: 1366,
          unitPrecision: 5,
          // propList: ['*', '!font-size'],
          propList: ['*'],
          viewportUnit: 'vw',
          fontViewportUnit: 'vw',
          selectorBlackList: ['.ignore', '.keep-px'],
          minPixelValue: 2,
          mediaQuery: true,
          replace: true,
          exclude: [/node_modules/],
          landscape: true,
          landscapeUnit: 'vw',
          landscapeWidth: 1366,
        }),
        autoprefixer({
          overrideBrowserslist: ['last 2 versions', 'iOS >= 9', 'Safari >= 9'],
        }),
      ],
    },
  },
  plugins: [
    vue(),
    checker({
      typescript: true, // 启用 TypeScript 检查
      eslint: {
        lintCommand: 'eslint "./src/**/*.{ts,tsx,vue}"', // 可选：同时启用 ESLint
      },
      overlay: true, // 在浏览器中显示错误覆盖层
    }),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
});
